﻿using System;
using System.Collections.Generic;
using System.Text;

namespace dllLink
{
    // modèle de Vasicek (taux d'intérêts)
    internal class ModelVasicek : Model
    {
        private double a;
        private double b;
        private double sigma;

        internal override void mSetParameters(Estimator theEstimator)
        {
            try
            {
                double[] myRes = ((VasicekEstimator)theEstimator).mComputeParams();
                a = myRes[0];
                b = myRes[1];
                sigma = myRes[2];
            }
            catch
            {
                throw new Exception("Wrong Estimator for the Vasicek Model");
            }
        }

        internal override void mSetParameters(double[] theParams)
        {
            if (theParams.GetLength(1) < 3)
            {
                throw new Exception("Vasicek model needs 3 parameters");
            }
            a = theParams[0];
            b = theParams[1];
            sigma = theParams[2];
        }

        //diffusion du prix
        internal override void mDiffuse(ref double theCurrentPrice, double[] theParams)
        {
            double myWi = theParams[0];
            theCurrentPrice += a*(b-theCurrentPrice)* mvDt + sigma * mvSqrtDt*myWi;
            theCurrentPrice = Math.Abs(theCurrentPrice); // défensif à la CIR
        }
    }
}
